package DigitalMe.client;

import hostconfig.HostConfig;

import java.io.IOException;

import java.net.Socket;
import java.net.UnknownHostException;

import communication.Communication;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class client extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        final Button button = (Button) findViewById(R.id.button1);
        
        button.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v)
            {
                button.setText("basildi");
                
                try 
                {
                  Socket socket =new Socket(HostConfig.getHostAddress(), HostConfig.getPort());
                  Communication communication = new Communication(socket);
                  try
                  {
                	  button.setText(communication.getMessage());
                  }
                  catch (ClassNotFoundException e)
                  {
                	  // TODO Auto-generated catch block
                	  button.setText(e.getMessage());
                  }
                  communication.sendMessage("Merhaba");
                  socket.close();
                } 
                catch (UnknownHostException e)
                {
                  //e.printStackTrace();
                	button.setText(e.getMessage());
                }
                catch (IOException e)
                {
                  button.setText(e.getMessage());
                  //e.printStackTrace();
                }
            }
        });

    }
}